package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class SelPictureAdapter extends StkProviderMultiAdapter<SelectMediaEntity> {

    public SelPictureAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(125));
        addItemProvider(new SelPictureProvider());
    }

    private class SelPictureProvider extends BaseItemProvider<SelectMediaEntity> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_picture;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, SelectMediaEntity bean) {
            Glide.with(getContext()).load(bean.getPath())
                    .into((ImageView) baseViewHolder.getView(R.id.ivSelPictureItemImg));
            if (bean.isChecked()) {
                baseViewHolder.getView(R.id.ivSelPictureItemSel).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.llSelPictureItemBg).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivSelPictureItemSel).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.llSelPictureItemBg).setVisibility(View.GONE);
            }
        }
    }
}
